package com.nxhz.service;


import com.nxhz.dao.fbsone.mapper.DemoOneMapper;
import com.nxhz.dao.fbstwo.mapper.DemoTwoMapper;

import com.nxhz.domain.DemoOne;
import com.nxhz.domain.DemoTwo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.DemoMaster;
import com.ruoyi.system.mapper.DemoMasterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



/**
 * com.nxhz.service
 *
 * @author jierui
 * @version v1.0
 * @date 2020/11/27
 * 描述：TODO
 */
@Service
public class ITestSourceService {

    @Autowired
    private DemoMasterMapper demoMasterMapper;

    @Autowired
    private DemoOneMapper demoOneMapper;

    @Autowired
    private DemoTwoMapper demoTwoMapper;

    /**
     * 测试主库与数据源source_one
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult testMasterAndOne(int id){
        String name="testMasterAndOne";
        int r = demoMasterMapper.insert(new DemoMaster(id,name+id));
        int row = demoOneMapper.insert(new DemoOne(id, name+id));

        if(r<0 || row<0){
            throw new RuntimeException();
        }
        return AjaxResult.success();
    }


    /**
     * 测试主库与数据源source_two
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult testMasterAndTwo(int id){
        String name="testMasterAndTwo";
        int r = demoMasterMapper.insert(new DemoMaster(id,name+id));
        int row = demoTwoMapper.insert(new DemoTwo(id, name+id));

        if(r<0 || row<0){
            throw new RuntimeException();
        }
        return AjaxResult.success();
    }


    /**
     * 测试数据源source_one 与 source_two
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult testOneAndTwo(int id){
        String name="testOneAndTwo";
        int r = demoOneMapper.insert(new DemoOne(id,name+id));
        int row = demoTwoMapper.insert(new DemoTwo(id, name+id));

        if(r<0 || row<0){
            throw new RuntimeException();
        }
        return AjaxResult.success();
    }


    /**
     * 测试数据源mater与source_one、source_two
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult testMasterAndOneAndTwo(int id){
        String name="testMasterAndOneAndTwo";
        int r = demoOneMapper.insert(new DemoOne(id,name+id));
        int row = demoTwoMapper.insert(new DemoTwo(id, name+id));
        int m = demoMasterMapper.insert(new DemoMaster(id, name+id));

        if(r<0 || row<0 || m<0){
            throw new RuntimeException();
        }
        return AjaxResult.success();
    }


}
